using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class MessagesListPage : BasePage
	{
		private const string TAG = "MessagesListPage";
		private EventWatcher MassMsgModifyWatcher;
		private bool isPageIn = true;
		public bool hasMassMsgAddFlag;
		private MMObservableCollection<MassMsg, MassSendListItem> mDataList = new MMObservableCollection<MassMsg, MassSendListItem>();
		private ApplicationBar mBar;
		private ApplicationBarIconButton pluginSettingButton;
		private ApplicationBarIconButton newMassSendButton;
		private Button ShowMoreBtn;
		private Visibility showMoreVisbility = 1;
		private ScrollViewer chatListScroll;
		private VoiceService mVoiceService;
		internal Grid LayoutRoot;
		internal Grid MassSendTitle;
		internal StackPanel TitleArea;
		internal EmojiText PageTitle;
		internal Grid MassSendList;
		internal MMListBox MassMsgList;
		internal Grid MassSendIntro;
		internal TextBlock txtPluginDetail;
		internal Button btnNewMassSend;
		internal MediaElement MMAudioPlayer;
		private bool _contentLoaded;
		public MessagesListPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.MessagesListPage_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.MessagesListPage_Unloaded));
		}
		private void MessagesListPage_Loaded(object sender, RoutedEventArgs e)
		{
			this.PlayVoiceInit();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				if (!this.isPageIn && this.hasMassMsgAddFlag)
				{
					this.MassMsgList.ScrollToLastWithAnimation();
					this.hasMassMsgAddFlag = false;
				}
				this.MassMsgList.IsAutoToBottom = false;
			});
		}
		private void MessagesListPage_Unloaded(object sender, RoutedEventArgs e)
		{
			this.PlayVoiceUnit();
			this.isPageIn = false;
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.PageTitle.Foreground = R.theme.CHAT_TITLE_BRUSH;
			this.LayoutRoot.set_Background(R.theme.CHAT_BK_BRUSH);
			this.InitMsg();
		}
		protected override void OnPageOut()
		{
		}
		protected override void OnPageBack()
		{
		}
		private void InitMsg()
		{
			this.MassMsgList.set_ItemsSource(null);
			this.MassMsgList.IsAutoToBottom = true;
			MassMsgMgr.attachMsgData(this.mDataList, this);
			this.mDataList.Bind(this.MassMsgList);
			if (this.mDataList != null && Enumerable.Count<MassMsg>(this.mDataList) != 0)
			{
				this.showListView();
				if (MassMsgMgr.CanExpand())
				{
					this.showMoreVisbility = 0;
				}
				else
				{
					this.showMoreVisbility = 1;
				}
				this.RefreshMoreBtn();
				return;
			}
			Log.smethod_1("MessagesListPage", "MsgInit,mDataList == null");
			this.showNoMsgView();
		}
		private void InitWatcher()
		{
		}
		private void UnitWatcher()
		{
		}
		private ApplicationBar GetApplicationBarOneButton()
		{
			if (this.mBar == null)
			{
				this.mBar = new ApplicationBar();
				this.mBar.set_IsMenuEnabled(true);
				this.mBar.set_IsVisible(true);
				if (this.mBar != null)
				{
					this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
					this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
				}
				this.pluginSettingButton = new ApplicationBarIconButton(new Uri("/Source/Plugin/Common/Resource/Img/Plugin_Setting.png", 2));
				this.pluginSettingButton.set_Text(strings.Set_Plugin_Setting);
				this.pluginSettingButton.add_Click(new EventHandler(this.pluginSettingButton_Click));
				this.mBar.get_Buttons().Add(this.pluginSettingButton);
				return this.mBar;
			}
			if (this.mBar.get_Buttons().get_Count() == 1)
			{
				return this.mBar;
			}
			this.mBar.get_Buttons().Remove(this.newMassSendButton);
			return this.mBar;
		}
		private ApplicationBar GetApplicationBarTwoButton()
		{
			if (this.mBar == null)
			{
				this.mBar = new ApplicationBar();
				this.mBar.set_IsMenuEnabled(true);
				this.mBar.set_IsVisible(true);
				if (this.mBar != null)
				{
					this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
					this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
				}
				this.pluginSettingButton = new ApplicationBarIconButton(new Uri("/Source/Plugin/Common/Resource/Img/Plugin_Setting.png", 2));
				this.pluginSettingButton.set_Text(strings.Set_Plugin_Setting);
				this.pluginSettingButton.add_Click(new EventHandler(this.pluginSettingButton_Click));
				this.newMassSendButton = new ApplicationBarIconButton(new Uri("/Source/Plugin/MassSend/Resource/Img/MassSend_New.png", 2));
				this.newMassSendButton.set_Text(strings.MassSend_CreateNewAppBar);
				this.newMassSendButton.add_Click(new EventHandler(this.newMassSendButton_Click));
				this.mBar.get_Buttons().Add(this.newMassSendButton);
				this.mBar.get_Buttons().Add(this.pluginSettingButton);
				return this.mBar;
			}
			if (this.mBar.get_Buttons().get_Count() == 2)
			{
				return this.mBar;
			}
			this.newMassSendButton = new ApplicationBarIconButton(new Uri("/Source/Plugin/MassSend/Resource/Img/MassSend_New.png", 2));
			this.newMassSendButton.set_Text(strings.MassSend_CreateNewAppBar);
			this.newMassSendButton.add_Click(new EventHandler(this.newMassSendButton_Click));
			this.mBar.get_Buttons().Add(this.newMassSendButton);
			return this.mBar;
		}
		private void pluginSettingButton_Click(object sender, EventArgs e)
		{
			base.GoToPage("/Source/Plugin/PluginSettingPage.xaml", new object[]
			{
				PluginManager.findPluginByName("MassSend")
			}, false);
			for (int i = 0; i < PageManager.getInstance().basePageList.get_Count(); i++)
			{
				BasePage basePage = PageManager.getInstance().basePageList.get_Item(i);
				if (basePage is PluginSettingPage)
				{
					PluginSettingPage pluginSettingPage = basePage as PluginSettingPage;
					if (pluginSettingPage.GetPluginName() == "MassSend")
					{
						PageManager.getInstance().PopPage();
						return;
					}
				}
			}
		}
		private void newMassSendButton_Click(object sender, EventArgs e)
		{
			object[] array = new object[2];
			array[0] = ChoosePeoplePage.ChoosePeoplePageFrom.MassSend;
			object[] object_ = array;
			base.GoToPage("/Source/Plugin/MassSend/UI/ChoosePeoplePage.xaml", object_, false);
		}
		private void ShowMoreBtn_Loaded(object sender, RoutedEventArgs e)
		{
			this.ShowMoreBtn = (sender as Button);
			this.RefreshMoreBtn();
		}
		private void ShowMoreBtn_Click(object sender, RoutedEventArgs e)
		{
			int num = 1;
			MassMsgMgr.ExpandMassMsgList();
			if (MassMsgMgr.CanExpand())
			{
				this.showMoreVisbility = 0;
			}
			else
			{
				this.MassMsgList.Focus();
				this.showMoreVisbility = 1;
				num++;
			}
			this.MassMsgList.LockScroll(num);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.RefreshMoreBtn();
			});
		}
		public void RefreshMoreBtn()
		{
			if (this.ShowMoreBtn == null)
			{
				return;
			}
			if (MassMsgMgr.CanExpand())
			{
				this.showMoreVisbility = 0;
			}
			else
			{
				this.showMoreVisbility = 1;
			}
			this.ShowMoreBtn.set_Content(strings.ChatMoreButtonTitle);
			this.ShowMoreBtn.set_Visibility(this.showMoreVisbility);
		}
		private void ScrollViewer_Loaded(object sender, RoutedEventArgs e)
		{
			this.chatListScroll = (sender as ScrollViewer);
		}
		private void btnNewMassSend_Click(object sender, RoutedEventArgs e)
		{
			object[] array = new object[2];
			array[0] = ChoosePeoplePage.ChoosePeoplePageFrom.MassSend;
			object[] object_ = array;
			base.GoToPage("/Source/Plugin/MassSend/UI/ChoosePeoplePage.xaml", object_, false);
		}
		private void PlayVoiceInit()
		{
			if (this.mVoiceService == null)
			{
				this.mVoiceService = new VoiceService(this.MMAudioPlayer);
				this.mVoiceService.Init();
			}
		}
		private void PlayVoiceUnit()
		{
			if (this.mVoiceService != null)
			{
				this.mVoiceService.UnInit();
				this.mVoiceService = null;
			}
		}
		public void VoiceItemClick(string string_0, MassSendVoiceItem massVoiceItem)
		{
			if (this.mVoiceService == null)
			{
				this.PlayVoiceInit();
			}
			this.mVoiceService.ClickVoice(string_0, massVoiceItem);
		}
		public void showListView()
		{
			this.MassSendIntro.set_Visibility(1);
			this.MassSendList.set_Visibility(0);
			base.set_ApplicationBar(this.GetApplicationBarTwoButton());
		}
		public void showNoMsgView()
		{
			this.MassSendList.set_Visibility(1);
			this.MassSendIntro.set_Visibility(0);
			base.set_ApplicationBar(this.GetApplicationBarOneButton());
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (!cancelEventArgs_0.get_Cancel())
			{
				cancelEventArgs_0.set_Cancel(true);
				ItemFlyInAndOutAnimations.TitleFlyOut(this);
				base.get_Dispatcher().BeginInvoke(delegate
				{
					base.GoBack();
				});
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/MassSend/UI/MessagesListPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.MassSendTitle = (Grid)base.FindName("MassSendTitle");
			this.TitleArea = (StackPanel)base.FindName("TitleArea");
			this.PageTitle = (EmojiText)base.FindName("PageTitle");
			this.MassSendList = (Grid)base.FindName("MassSendList");
			this.MassMsgList = (MMListBox)base.FindName("MassMsgList");
			this.MassSendIntro = (Grid)base.FindName("MassSendIntro");
			this.txtPluginDetail = (TextBlock)base.FindName("txtPluginDetail");
			this.btnNewMassSend = (Button)base.FindName("btnNewMassSend");
			this.MMAudioPlayer = (MediaElement)base.FindName("MMAudioPlayer");
		}
	}
}
